Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support setting the pythonpath in configuration YAMLs #1454

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rpoisel
Copy link
Contributor

@rpoisel rpoisel commented Jul 30, 2024

Description

The pythonpath key allows specifying additional directories to be added to the Python search path (sys.path). This is particularly useful for including directories that contain Python modules and packages which are not installed in the standard library or not in the current directory.

Relative paths are resolved relative to the configuration file's location.

Specifying this option enables the environment to locate and import modules that are not in the default Python path.

Checklist

  • Documentation for the feature
  • Tests for the feature
  • The arguments and description in doc/configuration.rst have been updated
  • Add a section on how to use the feature to doc/usage.rst
  • Add a section on how to use the feature to doc/development.rst
  • PR has been tested
  • Man pages have been regenerated

@rpoisel rpoisel force-pushed the dev-set-pythonpath-in-config branch 4 times, most recently from a1101cf to 6b37aa9 Compare July 30, 2024 14:05
@Emantor
Copy link
Member

Emantor commented Jul 30, 2024

Isn't this covered by the imports property already?

@rpoisel rpoisel force-pushed the dev-set-pythonpath-in-config branch 3 times, most recently from 6ba89b7 to 26f197c Compare July 30, 2024 18:22
@rpoisel
Copy link
Contributor Author

rpoisel commented Jul 30, 2024

Isn't this covered by the imports property already?

My use-case was to load modules and packages from relative paths or non-standard locations. In my situation, I want to use shared code that has been added to my projects as git submodules.

Making these modules/packages available could also be done by setting the PYTHONPATH environment variable somewhere in the context of any labgrid-using python code. However, I wanted to make this part of the configuration, thus I introduced the pythonpath property.

Could you please have a look into the integration tests of this functionality?

@rpoisel rpoisel force-pushed the dev-set-pythonpath-in-config branch from 26f197c to 4d67a63 Compare July 31, 2024 10:37
@rpoisel
Copy link
Contributor Author

rpoisel commented Aug 4, 2024

The pythonpath property is, in my opinion, similar to the pythonpath configuration option in pytest. You can find more details here: pytest pythonpath.

By setting this variable, tools like labgrid-client will also search the specified paths for imported modules and packages.

@Emantor
Copy link
Member

Emantor commented Aug 5, 2024

I am not convinced we should support two different mechanics for module imports. The imports functionality is narrower in scope and IMO suites the use case for in test case strategies quite well. The user can still set the PYTHONPATH explicitly outside of labgrid to make other modules available. @jluebbe, @Bastian-Krause whats your opinion on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants